package com.wang.example.netty.codec.other;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.CharsetUtil;

import java.util.List;

/**
 * @author suzhe
 * @date 2019/1/27
 */
public class TestDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        //转为字符串
        String msgStr = in.toString(CharsetUtil.UTF_8);
        String[] msgs = msgStr.split("&");
        if (msgs != null){
            for (int i = 0;i < (msgs.length-1);i++){
                out.add(msgs[i]);
            }
        }
    }
}
